package middleware

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

// Response 标准响应结构
type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

// ResponseSuccess 成功响应
func ResponseSuccess(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, Response{
		Code:    http.StatusOK,
		Message: "success",
		Data:    data,
	})
}

// ResponseError 错误响应
func ResponseError(c *gin.Context, code int, message string) {
	c.JSON(code, Response{
		Code:    code,
		Message: message,
	})
}

// ResponseBadRequest 400错误响应
func ResponseBadRequest(c *gin.Context, message string) {
	ResponseError(c, http.StatusBadRequest, message)
}

// ResponseUnauthorized 401错误响应
func ResponseUnauthorized(c *gin.Context, message string) {
	ResponseError(c, http.StatusUnauthorized, message)
}

// ResponseForbidden 403错误响应
func ResponseForbidden(c *gin.Context, message string) {
	ResponseError(c, http.StatusForbidden, message)
}

// ResponseNotFound 404错误响应
func ResponseNotFound(c *gin.Context, message string) {
	ResponseError(c, http.StatusNotFound, message)
}

// ResponseInternalError 500错误响应
func ResponseInternalError(c *gin.Context, message string) {
	ResponseError(c, http.StatusInternalServerError, message)
}

// ResponseTooManyRequests 429错误响应
func ResponseTooManyRequests(c *gin.Context, message string) {
	ResponseError(c, http.StatusTooManyRequests, message)
}
